package com.luhan.fmmall.controller;

import com.luhan.fmmall.service.ProductCommentsService;
import com.luhan.fmmall.service.ProductService;
import com.luhan.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供商品信息相关接口",tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private ProductCommentsService productCommentsService;

    @ApiOperation("商品基本信息查询接口")
    @GetMapping("/detail-info/{pid}")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid){
        return productService.getProductBasicInfo(pid);
    }

    @ApiOperation("商品参数信息查询接口")
    @GetMapping("/detail-params/{pid}")
    public ResultVO getProductParams(@PathVariable("pid") String pid){
        return productService.getProductParamsByproductId(pid);
    }

    @ApiOperation("商品评论信息查询接口")
    @GetMapping("/detail-comments/{pid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示的条数",required = true)
    })
    public ResultVO getProductComments(@PathVariable("pid") String pid,int pageNum,int limit){
        return productCommentsService.listProductCommentsByProductId(pid,pageNum,limit);
    }

    @ApiOperation("商品评论数量查询接口")
    @GetMapping("/detail-commontscount/{pid}")
    public ResultVO getCommentsCount(@PathVariable("pid") String pid){
        return productCommentsService.getCommentsCountByProductId(pid);
    }

    @ApiOperation("根据类别查询商品接口")
    @GetMapping("/listbycid/{cid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示的条数",required = true)
    })
    public ResultVO getProductsByProductId(@PathVariable("cid")int cid,int pageNum,int limit){
        ResultVO resultVO = productService.getProductsByCategId(cid, pageNum, limit);
        return resultVO;
    }

    @ApiOperation("根据类别查询商品品牌接口")
    @GetMapping("/listbrands/{cid}")
    @ApiImplicitParam(dataType = "int",name = "cid",value = "商品类别id",required = true)
    public ResultVO getBrandByCategoryId(@PathVariable("cid")int cid){
        ResultVO resultVO = productService.getBrandByCategoryId(cid);
        return resultVO;
    }

    @ApiOperation("根据关键字查询商品接口")
    @GetMapping("/listbykeyword")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "keyword",value = "关键字",required = true),
            @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示的条数",required = true)
    })
    public ResultVO searchProduct(String keyword,int pageNum,int limit){
        ResultVO resultVO = productService.searchProduct(keyword, pageNum, limit);
        return resultVO;
    }

    @ApiOperation("根据关键字查询商品品牌接口")
    @GetMapping("/listbrands-keyword")
    @ApiImplicitParam(dataType = "String",name = "keyword",value = "关键字",required = true)
    public ResultVO getBrandByKeyword(String keyword){
        ResultVO resultVO = productService.getBrandByKeyword(keyword);
        return resultVO;
    }
}
